<?php

use yii\helpers\Url;
$this->addCssFile([
    "css/upload.css",
    "plugins/webuploader/webuploader.css",
    "static/css/uploads.css"
]);

$this->addJsFile([
    "plugins/webuploader/webuploader.min.js",
    "js/webupload.js"
]);
$this->inline("title","添加案例");
?>
<div class="panel">
    <div class="panel-body">
        <div class="row">
            <div class="col-sm-12">
                <div class="card-box">
                    <h4 class="m-t-0 m-b-30 header-title"><b>添加案例</b></h4>
                    <p class="text-muted font-13 m-b-30">
                        爱生活、爱分享、爱编程！
                    </p>
                    <form id="case" onsubmit="return false">

                        <input type="hidden" name="<?=Yii::$app->request->csrfParam?>" value="<?=Yii::$app->request->csrfToken?>">
                        <div class="row">
                            <div class="col-sm-6">
                                <div class="form-group">
                                    <label>名称</label>
                                    <input class="form-control" name="name" placeholder="请输入单位或个人名称">
                                </div>
                            </div>
                            <div class="col-sm-6">
                                <div class="form-group">
                                    <label>日期</label>
                                    <input class="form-control" name="time" placeholder="日期：2017/07/02" >
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-sm-6">
                                <div class="form-group">
                                    <label>标签</label>
                                    <input class="form-control" name="tag" placeholder="科技，服务，金融等" >
                                </div>
                            </div>
                            <div class="col-sm-6">
                                <div class="form-group">
                                    <label>QQ</label>
                                    <input class="form-control" name="qq" placeholder="QQ号码" >
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-sm-6">
                                <div class="form-group">
                                    <label>微信</label>
                                    <input class="form-control" name="wechat" placeholder="微信号" >
                                </div>
                            </div>
                            <div class="col-sm-6">
                                <div class="form-group">
                                    <label>手机号</label>
                                    <input class="form-control" name="tel" placeholder="手机号" >
                                </div>
                            </div>
                        </div>

                        <div class="form-group">
                            <label>描 述</label>
                            <textarea class="form-control" name="desc" placeholder="描述：这是一个神奇的网站"><?php echo isset($request['desc'])?$request['desc']:"";?></textarea>
                        </div>
                        <div class="form-group">
                            <label>项目地址</label>
                            <input class="form-control" name="url" placeholder="https://www.xxshare.cn" >
                        </div>

                        <label>案例图片</label>
                        <div id="container">
                                <!--头部，相册选择和格式选择-->
                            <div id="uploader">
                                <div class="queueList">
                                    <div id="dndArea" class="placeholder">
                                        <div id="filePicker"></div>
                                        <p>或将照片拖到这里，单次最多可选300张</p>
                                    </div>
                                </div>
                                <div class="statusBar" style="display:none;">
                                    <div class="progress">
                                        <span class="text">0%</span>
                                        <span class="percentage"></span>
                                    </div><div class="info"></div>
                                    <div class="btns">
                                        <div id="filePicker2"></div><div class="uploadBtn">开始上传</div>
                                    </div>
                                </div>
                            </div>
                            <input id="picture" type="hidden" name="picture">
                        </div>
                        <div class="checkbox checkbox-primary checkbox-inline">
                            <input <?php echo isset($request['status']) && $request['status'] == 0?"checked":"";?> type="checkbox" value="0" name="status"><label>提交审核</label>
                        </div>
                        <div class="checkbox checkbox-primary checkbox-inline">
                            <input <?php echo isset($request['status']) && $request['status'] == 1?"checked":"";?> type="checkbox" value="1" name="status"><label>申请置顶</label>
                        </div>
                        <div class="checkbox checkbox-primary checkbox-inline">
                            <input <?php echo isset($request['status']) && $request['status'] == 2?"checked":"";?> type="checkbox" value="2" name="status"><label>立即发布</label>
                        </div>
                        <div class="form-group text-right m-b-0">
                            <button class="btn btn-primary waves-effect waves-light" onclick="saveObj.save()" type="button">
                                提 交
                            </button>
                            <button type="reset" class="btn btn-default waves-effect waves-light m-l-5">
                                重 置
                            </button>
                            <button onclick="location.href='<?=Url::toRoute('/banner')?>'" type="button" class="btn btn-default waves-effect waves-light m-l-5">
                                返 回
                            </button>
                        </div>
                    </>
                </div>
            </div>
        </div>
    </div>
</div>

<?php $this->addJsFile(['js/upload.js']);?>
<?php $this->beginBlock("jsText","append");?>
<script type="text/javascript">

    //图片上传插件
    var formData = {};
    var csrfToken = $('meta[name="csrf-token"]').attr("content");
    var csrfParam = $('meta[name="csrf-param"]').attr("content");
    // 请求数据
    formData[csrfParam] = csrfToken;
    formData['category'] = 'image';
    formData['action'] = 'case';
    //图片上传地址
    uploadApi = '<?php echo Yii::$app->urlManager->createUrl(['api/upload/index'])?>';

    var saveObj = {
        ajaxLock:false,
        save:function () {
            that = this;
            var data = $("#case").serialize();
            var submitUrl = "<?php echo Yii::$app->urlManager->createUrl(['case/save'])?>";

            if (that.ajaxLock)return false;
            that.ajaxLock = true;

            $.ajax({
                data:data,
                url:submitUrl,
                type:'post',
                dataType:'json',
                success:function (resp) {
                    $.Notification.autoHideNotify(resp.state, 'bottom right', '提示信息',resp.message);
                    that.ajaxLock = false;
                },
                error:function () {
                    that.ajaxLock = false;
                }
            });
        }
    };
</script>
<?php $this->endBlock();?>
